package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.BaseTrademark;
import com.atguigu.gmall.model.product.CategoryTrademarkVo;
import com.atguigu.gmall.product.service.BaseCategoryTrademarkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 里
 * @Data:2021/11/11/0:21
 * @Description:
 */
@RestController
@RequestMapping("/admin/product/baseCategoryTrademark")
public class BaseCategoryTrademarkController {
    @Autowired
    private BaseCategoryTrademarkService baseCategoryTrademarkService;

    @GetMapping("findTrademarkList/{category3Id}")
    public Result findTrademarkList (@PathVariable Long category3Id){
        //调用服务层 查询品牌分类列表
        List<BaseTrademark> baseCategoryTrademarkList =  baseCategoryTrademarkService.findTrademarkList(category3Id);
        //返回数据
        return Result.ok(baseCategoryTrademarkList);
    }

    @DeleteMapping("remove/{category3Id}/{trademarkId}")
    public Result  removeBaseCategoryTrademarkById(@PathVariable Long category3Id,
                                                   @PathVariable Long trademarkId) {
        baseCategoryTrademarkService.removeBaseCategoryTrademarkById(category3Id,trademarkId);
        return Result.ok();
    }

    // 根据三级分类id获取未关联的品牌数据集合
    @GetMapping("findCurrentTrademarkList/{category3Id}")
    public Result findCurrentTrademarkList(@PathVariable Long category3Id) {
        List<BaseTrademark> baseTrademarkList =  baseCategoryTrademarkService.findCurrentTrademarkList(category3Id);
        return Result.ok(baseTrademarkList);
    }

    @PostMapping("save")
    public Result save (@RequestBody CategoryTrademarkVo categoryTrademarkVo) {
        baseCategoryTrademarkService.save(categoryTrademarkVo);
        return Result.ok();
    }


}
